package com.kcht.sylyg08.service.impl;

import com.kcht.sylyg08.dao.ITransSequencesDao;
import com.kcht.sylyg08.service.IGenerateEpcNo;

import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
  *
  * @Package:        com.kcht.sylyg08.service.impl
  * @Description:    生成 EPC 码
  * @Author:         lenovo
  * @CreateDate:     2019/5/20 14:51
 */
@Singleton
@Startup
public class GenerateEpcNo implements IGenerateEpcNo {

    @EJB
    private ITransSequencesDao transSequencesDao;

    @Override
    public String getEPCNo() throws Exception {
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        StringBuilder caseNo = new StringBuilder();
        caseNo.append(sdf1.format(date));
        caseNo.append(String.format("%010d", transSequencesDao.getTransnSequences("SYLYG08_SEQ", date)));
        return caseNo.toString();
    }
}
